/**********
modules written by battery 

***/
var cmdHistory = {
    name:"history",
    help:"view/clear cmd's history.",
    run: function(args, callback){
	this.callback = callback;
	if (args.length > 0) {
		if (args[0] == "clear")
		{
			this.clear();
		} else if (args[0] == "view")	
		{
			this.view();
		}
	} else
	{
		this.view();
	}
    },
    clear: function() {
       	Daush.Gui.history = [];
       	Daush.Gui.historyIndex = 0;
	Daush.Cookie.eraseCookie("history");

	this.callback();
    },
    view: function() {
	var output = document.createElement('div');
	for (var i = 0; i < Daush.Gui.history.length; i++) {
		output.innerHTML += Daush.Gui.history[i];
		if (Daush.Gui.history.length - 1 > i)
			output.innerHTML += "<br/>";
	}
	
	this.callback(output);
    }
};
Daush.Interpreter.add_module( cmdHistory );

var cmdJs = {
name:"js",
help:"javascript console.",
run:function(args, callback) {
	this.callback = callback;
	var cmd = args.join(" ");
	try 
	{
		eval(cmd);
		callback(document.createTextNode('success!'));
	}
	catch(err)
	{
		callback(document.createTextNode("err: " +err.message));
	}
}
};
Daush.Interpreter.add_module( cmdJs );

var cmdSms = {
name:"sms",
help:"send sms message",
id:"",
passwd:"",
run:function(args, callback) {
	/*
	try 
	{	
		var image = document.createElement('iframe');
		image.className = 'sms';
		image.src = "http://edusharesms.cafe24.com/sms_send.php?user_id=" + this.id + "&passwd=" + this.passwd
                + "&rphone1=" + args[0] + "&rphone2=" + args[1] + "&rphone3="+ args[2]
                + "&sphone1=000&sphone2=0000&sphone3=0000&msg=" + args[3];
		image.style.display = 'none';
		callback(image);
	}
	catch(err)
	{
		callback(document.createTextNode("err: " +err.message));
	}*/
	callback(document.createTextNode('Coming soon.'));
}
};
Daush.Interpreter.add_module( cmdSms );

/*
var cmdTop10 = {
name:"top10",
help:"show Top10 Keywords",
run:function(args, callback) {
	var script = document.createElement('script');
	script.src = "http://apis.daum.net/ajax/rtissue.daum?apikey=221c3e61372992ed8e8f322bea3488963068e3f6";

	callback(script);
}
};
Daush.Interpreter.add_module( cmdTop10 );
*/
